package GSEA::Config::ProjectConfig ;

use strict ;
use warnings;

sub constrProjectConfig($$) #constructor
{
	my ($classe , my $projectFilePath ) = @_; 
	
	if( ! defined($projectFilePath)	){ die("argument 'projectFilePath' is not set , error");}

	
	my $this = {			
					"projectFilePath"	=> $projectFilePath,
					"alpha"				=> 0,
					"t"					=> 0,
					"p"					=> 0,
					"LFilePath"			=> "",
					"SFilePath"			=> "",					
				};
	
	bless ($this,$classe);  
	
	$this->readProjectFile();
	
	return $this;  
}


sub readProjectFile($)
{
	( my $this )= @_ ;
	
	my $projectFilePath = $this->{"projectFilePath"} ;
	my $counter = 0 ;

	my @SFile_path ;	

	if( -e $projectFilePath )
	{
		if( ! open(EXISTFILE , "<$projectFilePath") ) { die("huh.. error happened ! $! "); }
		
		my $line = "";
		while(<EXISTFILE>)
		{
			$counter++;
			$line = $_ ; 
			chomp($line);
			#print("$counter>$line\n");
			
			
			if( $counter == 1)
			{
				$this->{"alpha"} = $line ;
			}
			else
			{ 
				if ( $counter == 2)
				{
					$this->{"t"} = $line ;
				}
				else
				{
					if ( $counter == 3)
					{
						 $this->{"p"}  = $line ;
					}
					else
					{
						if( $counter == 4 )
						{
							$this->{"LFilePath"} = $line ;
						}
						else
						{
						     if( defined($line) && ! ($line eq "") ){push( @SFile_path , $line );}	
						}
					}
				}
			}
			
		}
		
		# checking file integrity : 
		if( $counter < 5 ){die("error : project is incomplete, there is not enough information");}
		
		close(EXISTFILE);
		
		$this->{"SFilePath"} =  \ @SFile_path ;
	}

	
}


sub toString($)
{
	( my $this )= @_ ;
	
	my $return = "" ;
	
	$return .= "T=". $this->getTparameter() ;
	$return .= "\tP=". $this->getPparameter() ;
	$return .= "\nLfile=". $this->getLFilePath() ;
	
	my @sfiles = $this->getSFilePath();
	
	for( my $i = 0 ; $i < $#sfiles ; $i++ )
	{
		$return .= "\nSfile=". $sfiles[$i] ;
	}
	
	return $return;	 
}

sub getAlphaparameter($)
{
	( my $this )= @_ ;
	my $a = $this->{"alpha"} ;
	return $a ;	
}



sub getTparameter($)
{
	( my $this )= @_ ;
	my $t = $this->{"t"} ;
	return $t ;
}
	
 
sub getProjectFilePath($)
{
	( my $this )= @_ ;
	my $t = $this->{"projectFilePath"} ;
	return $t ;	
}

sub getPparameter($)
{
	( my $this )= @_ ;
	my $t = $this->{"p"} ;
	return $t ;	
}

sub getLFilePath($)
{
	( my $this )= @_ ;
	my $t = $this->{"LFilePath"} ;
	return $t ;	
}

sub getSFilePath($)
{
	( my $this )= @_ ;
	
	my $t = $this->{"SFilePath"} ;
	my @sfiles = @{$t} ;
	
	return @sfiles ;	
}


1;